Skip to content

feature about chat completions reasoning, support claude model enable thinking & interleaved thinking , and support gemini-3-x thinking#164

Closed
caozhiyuan wants to merge 17 commits into
ericc-ch:masterfrom
caozhiyuan:feature/chat-completions-reasoning
Closed

feature about chat completions reasoning, support claude model enable thinking & interleaved thinking , and support gemini-3-x thinking#164
caozhiyuan wants to merge 17 commits into
ericc-ch:masterfrom
caozhiyuan:feature/chat-completions-reasoning

Conversation

@caozhiyuan
Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to the translation logic between Anthropic and OpenAI message formats, especially around the new interleaved thinking protocol for Claude models. It adds support for thinking blocks in both streaming and non-streaming translation flows, updates protocol and API versions, and refines how message content is handled to ensure compatibility and correctness.

Anthropic <-> OpenAI translation improvements:

  • Added support for interleaved thinking protocol for Claude models, including injecting reminders and enforcing thinking block requirements in system and user prompts. Thinking blocks are now correctly mapped to and from OpenAI's reasoning_text and reasoning_opaque fields, with appropriate filtering and content handling. [1] [2] [3] [4] [5] [6] [7]
  • Updated the translation logic to include a thinking_budget parameter, calculated based on the model's capabilities and request payload, and passed through to copilot as needed. [1] [2]

Streaming translation and state handling:

  • Refactored the streaming translation logic to modularize event handling, explicitly manage thinking block state, and ensure correct emission of content and tool call blocks. This includes new helper functions for handling message start, thinking text, content, tool calls, and finish events. [1] [2] [3]
  • Updated the AnthropicStreamState interface and related state initialization to track thinkingBlockOpen. [1] [2]

Protocol and API version updates:

  • Bumped Copilot and API version numbers to 0.35.0 and 2025-10-01 respectively, and changed the openai-intent header from conversation-panel to conversation-agent for more accurate intent signaling. [1] [2]

Message content and tokenization:

  • Adjusted message token counting to ignore the reasoning_opaque field, preventing it from being double-counted in token calculations.
  • Refined message content mapping to separate text and thinking blocks, ensuring only text blocks are included in the main message content for OpenAI compatibility. [1] [2] [3]

Type and interface enhancements:

  • Extended the AnthropicThinkingBlock interface to include a signature field, supporting signature-based validation and filtering for thinking blocks.

These changes collectively ensure robust support for the new Claude thinking protocol, improve translation accuracy, and future-proof the integration with updated API versions.

caozhiyuan and others added 17 commits November 19, 2025 21:32
…g order when stream=false and exclude reasoning_opaque from token calculation in calculateMessageTokens
When account type is not specified or set to 'individual', use the default
api.githubcopilot.com URL instead of constructing a subdomain-based URL.

This restores previous behavior where business users could work without
explicitly specifying their account type, as the default URL works for both
individual and business accounts.

Only constructs account-type-specific URLs (api.business.githubcopilot.com,
api.enterprise.githubcopilot.com) when those account types are explicitly
specified.
fix: use default API URL when account type is individual
Copy link
Copy Markdown

@mrhanhan mrhanhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I believe that regularization could be used to transform the Claude model here, which would be better.

like:
image

function translateModelName(model: string): string {
  // Subagent requests use a specific model number which Copilot doesn't support
  if (model.startsWith("claude")) {
    const newModel = model.replaceAll(
      /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g,
      "$1.$2",
    )
    consola.log("Use Model:", model, newModel)
    return newModel
  }
  consola.log("Use Model:", model)
  return model
}

effect:
image

@caozhiyuan
Copy link
Copy Markdown
Contributor Author

caozhiyuan commented Jan 5, 2026

@mrhanhan Actually, this piece of translateModelName code is already useless . claude setting change like this

    "ANTHROPIC_BASE_URL": "http://localhost:4141",
    "ANTHROPIC_AUTH_TOKEN": "dummy",
    "ANTHROPIC_MODEL": "gpt-5.2",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "gpt-5.2",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "gpt-5-mini",
    "CLAUDE_CODE_SUBAGENT_MODEL": "gpt-5-mini",
    "DISABLE_NON_ESSENTIAL_MODEL_CALLS": "1",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "BASH_MAX_TIMEOUT_MS": "600000"

@caozhiyuan
Copy link
Copy Markdown
Contributor Author

caozhiyuan commented Jan 5, 2026

@caozhiyuan caozhiyuan requested a review from mrhanhan January 5, 2026 12:16
@caozhiyuan caozhiyuan closed this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants